export default  class Row{
    constructor(a,b,c,d){
        if(!a)a="";
        if(!b)b="";
        if(!c)c="";
        if(!d)d="";

        this.list=[a,b,c,d];
    }
    find(n){
        let res=this.list[n-1];
        if(res){
            return res;
        }
        return null;
    }
    save(n,data){
        this.list[n]=data;
    }

    /**
     * 对比 如果相同返回 true
     * 忽略对比值前面的0
     * n 从1计数
     * @param n
     * @param data
     * @returns {boolean}
     */
    is(n,data){
        let regex=/^[0]+/
        let d=data.replace(regex,"");
        let r=this.list[n-1].replace(regex,"");
        if(d===r) return true;
        return false;

    }
    //编码
    encoded(){
        let res=[]
        for(let i=0;i<4;i++){
            if(this.list[i] ||this.list[i]!=""){
                let works=  this.list[i].toString().split("");
                res.push(...works);
            }
            res.push("a")
        }
        res.length=res.length-1;
        return res;
    }
    //解码
    decode(words){
        let word='';
        let i=0;
        for(let l=0;l<words.length;l++){

            if('a' == words[l]){
                this.list[i]=word;
                i++;
                word='';
            }else {
                word+=words[l];
            }
        }
        this.list[i]=word;
    }
}
